package com.landian.commons.base.exception;

import lombok.Getter;

/**
 * @author caojl
 * @date: 2018-08-20
 * @time: 14:55
 */
public class RestException extends RuntimeException {

    public static RestException newInstance(String msg){
        return new RestException(msg);
    }

    public static RestException newInstance(Integer code, String msg){
        return new RestException(code, msg);
    }

    @Getter
    private Integer code;
    @Getter
    private String msg;

    public static Integer DEFAULT_ERROR_CODE = -1;
    /**
     * 权限不足
     */
    public static RestException UNAUTHORIZED = new RestException(Integer.valueOf(-401), "非法操作，权限不足");
    /**
     * 内容不存在
     */
    public static RestException NOT_FOUND = new RestException(Integer.valueOf(-404), "内容不存在");

    public RestException(String msg) {
        super(msg);
        this.code = DEFAULT_ERROR_CODE;
        this.msg = msg;
    }

    public RestException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }
}